local base = game_mode.netbase
local cross = class("cross_mode",base)

cross.roomMax = 20
cross.roomMin = 2
cross.roomLast = 60*10
cross.mapName = "cross"
cross.teamCount = 2
cross.itemGenCD = 30
cross.itemGenTypes = {1,2,3,4,5,6,7}
cross.npcGenCD = 5
cross.npcGenTypes = {1,2,3,4,5,6,7,8}
cross.npcGenCollCheck = true
cross.enablePlayerRebirth = true
cross.playerRebirthCD = 5
cross.playerBirthCollCheck = true
cross.playerGenTypes = {1,2,3,4,5,6,7,8}

function cross:getPlayerBirthPos(player)
    self.playerGenPos = self.playerGenPos or {}
    if self.playerGenPos[player.team] then return self.playerGenPos[player.team] end
    local pos = {
        minX = 1,
        maxX = self.map.w-1,
        minY = 1,
        maxY = self.map.h-1
    }
    if player.team == 1 then
        pos.maxY = 1
    elseif player.team == 2 then
        pos.minY = self.map.h-1
    end
    self.playerGenPos[player.team] = pos
    return pos
end

function cross:getNPCGenPos()
    if self.npcGenPos then return self.npcGenPos end
    self.npcGenPos = {
        minX = 1,
        maxX = self.map.w-1,
        minY = 1,
        maxY = self.map.h-1
    }
    return self.npcGenPos
end

function cross:onUpdate(dt)
    local t1_reach = self.teams[1][1]
    local t2_reach = self.teams[2][1]
    for i,player in pairs(self.teams[1]) do
        if player.tank.y < (self.map.h-2)*16 then
            t1_reach = false
        end
    end
    
    for i,player in pairs(self.teams[2]) do
        if player.tank.y > 32 then
            t2_reach = false
        end
    end
    if t1_reach then
        self:gameOver({team_1 = "win",team_2 = "lose"})
    elseif t2_reach then
        self:gameOver({team_2 = "win",team_1 = "lose"})
    end
end

return cross